package com.jxc.jxc01.grc.web;

import com.alibaba.fastjson.JSON;
import com.jxc.jxc01.grc.entity.RespResult;
import com.jxc.jxc01.grc.entity.Return;
import com.jxc.jxc01.grc.service.IReturnService;
import com.jxc.jxc01.grc.service.impl.IReturnServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(value = "/obscureReturn")
public class ObscureReturnServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        System.out.println("786543123");
        String procurement1 = request.getParameter("procurement");
        if (procurement1 != ""){
            int procurement = Integer.parseInt(procurement1);
            IReturnService returnService = new IReturnServiceImpl();
            List<Return> returns = returnService.queryReturnById(procurement);
            System.out.println(returns);
            if (returns != null && returns.size() > 0) {
                RespResult result = new RespResult();
                result.setCode(0);
                result.setMessage("ok");
                result.setCount(returns.size());
                result.setData(returns);
                HttpSession session = request.getSession();
                session.setAttribute("result",result);
                response.sendRedirect("caigoutuihuo.html");
            }
        }else {
            response.sendRedirect("caigoutuihuo.html");
        }

        writer.close();
    }
}
